% calculate_haemodynamics
% calculate standard haemodynamic parameters and fills in text boxes

HandleEditTextSV=findobj(gcf,'Tag','EditTextSV');
set(HandleEditTextSV,'String',num2str(round(max(VLV)-min(VLV))));

HandleEditTextPsys=findobj(gcf,'Tag','EditTextPsys');
set(HandleEditTextPsys,'String',num2str(round(max(Pao))));

HandleEditTextPdia=findobj(gcf,'Tag','EditTextPdia');
set(HandleEditTextPdia,'String',num2str(round(min(Pao))));

HandleEditTextPmean=findobj(gcf,'Tag','EditTextPmean');
set(HandleEditTextPmean,'String',num2str(round(mean(Pao))));

HandleEditTextLVEDV=findobj(gcf,'Tag','EditTextLVEDV');
set(HandleEditTextLVEDV,'String',num2str(round(max(VLV))));

% Forward and backward aortic flow

timeAOregurg=find(Qao<0);
if ~isempty(timeAOregurg)
	dummyAOregurg=gradient(cumtrapz(time(timeAOregurg),Qao(timeAOregurg)));
	wheredummyAOregurg=find(gradient(timeAOregurg)==1);
   AOLeak=sum(dummyAOregurg(wheredummyAOregurg));
	HandleEditTextTAOLeak=findobj(gcf,'Tag','EditTextTAOLeak');
	set(HandleEditTextTAOLeak,'String',num2str(length(wheredummyAOregurg)*t_interval));
	HandleEditTextPaoleak=findobj(gcf,'Tag','EditTextPaoleak');
	set(HandleEditTextPaoleak,'String',num2str(mean(Pao(timeAOregurg))));
else
   AOLeak=0;
	HandleEditTextTAOLeak=findobj(gcf,'Tag','EditTextTAOLeak');
	set(HandleEditTextTAOLeak,'String',num2str(0));
	HandleEditTextPaoleak=findobj(gcf,'Tag','EditTextPaoleak');
	set(HandleEditTextPaoleak,'String',num2str(0));
end   

HandleEditTextAOLeak=findobj(gcf,'Tag','EditTextAOLeak');
set(HandleEditTextAOLeak,'String',num2str(round(AOLeak)));

timeAOfwd=find(Qao>=0);
dummyAOfwd=gradient(cumtrapz(time(timeAOfwd),Qao(timeAOfwd)));
wheredummyAOfwd=find(gradient(timeAOfwd)==1);
AOFwd=sum(dummyAOfwd(wheredummyAOfwd));

HandleEditTextAOFwd=findobj(gcf,'Tag','EditTextAOFwd');
set(HandleEditTextAOFwd,'String',num2str(round(AOFwd)));


% Forward and backward mitral flow

timeMVregurg=find(Qmv<0);
if ~isempty(timeMVregurg)
	dummyMVregurg=gradient(cumtrapz(time(timeMVregurg),Qmv(timeMVregurg)));
	wheredummyMVregurg=find(gradient(timeMVregurg)==1);
	MVLeak=sum(dummyMVregurg(wheredummyMVregurg));
	HandleEditTextTMVLeak=findobj(gcf,'Tag','EditTextTMVLeak');
	set(HandleEditTextTMVLeak,'String',num2str(length(wheredummyMVregurg)*t_interval));
	HandleEditTextPLVleak=findobj(gcf,'Tag','EditTextPLVleak');
	set(HandleEditTextPLVleak,'String',num2str(mean(PLV(timeMVregurg))));
else
   MVLeak=0;
	HandleEditTextTMVLeak=findobj(gcf,'Tag','EditTextTMVLeak');
	set(HandleEditTextTMVLeak,'String',num2str(0));
	HandleEditTextPLVleak=findobj(gcf,'Tag','EditTextPLVleak');
	set(HandleEditTextPLVleak,'String',num2str(0));
end

HandleEditTextMVLeak=findobj(gcf,'Tag','EditTextMVLeak');
set(HandleEditTextMVLeak,'String',num2str(round(MVLeak)));

timeMVfwd=find(Qmv>=0);
dummyMVfwd=gradient(cumtrapz(time(timeMVfwd),Qmv(timeMVfwd)));
wheredummyMVfwd=find(gradient(timeMVfwd)==1);
MVFwd=sum(dummyMVfwd(wheredummyMVfwd));

HandleEditTextMVFwd=findobj(gcf,'Tag','EditTextMVFwd');
set(HandleEditTextMVFwd,'String',num2str(round(MVFwd)));



